package conson.tech.manage.facade.provider;

import conson.tech.base.sign.SignVerify;
import conson.tech.core.constant.SecurityConstants;
import conson.tech.core.response.Response;
import conson.tech.manage.api.coupons.form.CouponApplyForm;
import conson.tech.manage.coupons.service.CouponProviderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 优惠券公共
 * Created by guoxt on 2020/7/30.
 */
@RestController
@RequestMapping(SecurityConstants.PUBLICAPI)
@Slf4j
@SignVerify
public class CouponPublicProvider {

    @Autowired
    private CouponProviderService couponProviderService;

    /**
     * 外围系统优惠券，通知优惠券已核销
     * @param couponOperForm
     * @return
     */
    @PostMapping("/coupons/notify")
    public Response notifyCouponApplied(@RequestBody CouponApplyForm couponOperForm){
        log.info("CouponPublicProvider--> notifyCouponApplied input : {}",couponOperForm);
        if(couponOperForm.getCouponAppliedDetailDTOS() == null || couponOperForm.getCouponAppliedDetailDTOS().size() == 0)
        {
            return Response.fail("input param is empty");
        }
        return couponProviderService.appliedCoupon(couponOperForm.getCouponAppliedDetailDTOS());
    }
}
